package com.kexun;

import cn.hutool.core.io.file.FileReader;

import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.util.List;

public class DouyinLive {


    public static void main(String[] args) throws AWTException, InterruptedException {
        Robot robot = new Robot();

        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Clipboard clipboard = toolkit.getSystemClipboard();

        Thread.sleep(5000);
        Point mouseLocation = MouseInfo.getPointerInfo().getLocation();
        System.out.println("Mouse at x: " + mouseLocation.x + ", y: " + mouseLocation.y);
        int x = mouseLocation.x;
        int y = mouseLocation.y;

        FileReader fileReader = new FileReader("C:\\Users\\李冬\\Desktop\\幽默短句.txt");
        List<String> strings = fileReader.readLines();
        for (String string : strings) {
            //观看5s
            Thread.sleep(2000);

            clipboard.setContents(new StringSelection("[互粉][互粉][互粉][互粉][互粉][互粉][互粉]"+string), null);
            //移动鼠标
            robot.mouseMove(x, y);
            robot.mousePress(InputEvent.BUTTON1_MASK);
            robot.mouseRelease(InputEvent.BUTTON1_MASK);
            Thread.sleep(500);
            //ctrl+v
//            robot.keyPress(KeyEvent.VK_META);
            robot.keyPress(KeyEvent.VK_CONTROL);
            robot.keyPress(KeyEvent.VK_V);
//            robot.keyRelease(KeyEvent.VK_META);
            robot.keyRelease(KeyEvent.VK_CONTROL);
            robot.keyRelease(KeyEvent.VK_V);
            Thread.sleep(800);

            //回车发送
            robot.keyPress(KeyEvent.VK_ENTER);
            robot.keyRelease(KeyEvent.VK_ENTER);

        }


    }
}
